import { getGovernmentTestPaperDetailForPlan } from '@/api/Plan';
import { useSafeState } from 'ahooks';
import { Descriptions } from 'antd';
import { useEffect } from 'react';
import TestPaperItem from './TestPaperItem';

function TestPaperDetailForPlan(props: { coursewareId: string; resourceType?: string }) {
  const { coursewareId } = props;
  const [videCourseWareDetail, setVideCourseWareDetail] = useSafeState<any>();
  // <Drawer destroyOnClose={true} />
  useEffect(() => {
    //企业协会
    getGovernmentTestPaperDetailForPlan(coursewareId).then((res: any) => {
      const data: any = res.data;
      data.newShowQuestions = data.questionTypeList.map((quesItem: any) => {
        let name;
        const { questionType } = quesItem;
        if (questionType === 100) {
          name = '单选题';
        } else if (questionType === 200) {
          name = '多选题';
        } else if (questionType === 300) {
          name = '判断题';
        }
        return {
          ...quesItem,
          name,
        };
      });
      console.log('--data.newShowQuestions--:', data.newShowQuestions);
      setVideCourseWareDetail(data);
    });
  }, []);

  return (
    <div className="courseware_drawer_content">
      {videCourseWareDetail && (
        <>
          <Descriptions column={2} className="ym_descriptions">
            <Descriptions.Item label="试卷名称" span={2}>
              {videCourseWareDetail.name}
            </Descriptions.Item>
            <Descriptions.Item label="及格分数" span={2}>
              <span>满分{videCourseWareDetail.totalScore}分，</span>&nbsp;&nbsp;
              <span>{videCourseWareDetail.passScore}分及格</span>
            </Descriptions.Item>
          </Descriptions>
          <Descriptions column={2} className="ym_descriptions">
            <Descriptions.Item label="" span={2}>
              <div style={{ width: '100%' }}>
                {videCourseWareDetail.newShowQuestions.map((paperItem: any, index: number) => (
                  <TestPaperItem
                    key={index}
                    index={index}
                    score={paperItem.score}
                    name={paperItem.name}
                    questions={paperItem.questionList}
                  />
                ))}
              </div>
            </Descriptions.Item>
          </Descriptions>
        </>
      )}
    </div>
  );
}

export default TestPaperDetailForPlan;
